package com.ruoyi.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.domain.CarBorder;
import com.ruoyi.domain.CarBorderQueryDTO;
import com.ruoyi.service.ICarBorderService;
import com.ruoyi.service.ICarWashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
@RestController
@RequestMapping("/carwash")
public class CarWashController extends BaseController {

    @Autowired
    private ICarWashService carWashService;

    /**
     * 查询洗车订单列表
     */
    @RequiresPermissions("orderManagement:carwash:list")
    @GetMapping("/list")
    public TableDataInfo list(CarBorderQueryDTO queryDTO)
    {
        startPage();
        return getDataTable(carWashService.selectCarBorderDetailList(queryDTO));
    }

    /**
     * 导出洗车订单列表
     */
    @RequiresPermissions("orderManagement:carwash:export")
    @Log(title = "洗车订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarBorderQueryDTO queryDTO)
    {
        List<CarBorder> list = carWashService.selectCarBorderList(queryDTO);
        ExcelUtil<CarBorder> util = new ExcelUtil<CarBorder>(CarBorder.class);
        util.exportExcel(response, list, "商家订单数据");
    }

    /**
     * 获取洗车订单详细信息
     */
    @RequiresPermissions("orderManagement:carwash:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(carWashService.selectCarBorderById(id));
    }

    /**
     * 新增洗车订单
     */
    @RequiresPermissions("orderManagement:carwash:add")
    @Log(title = "洗车订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarBorder carBorder)
    {
        return toAjax(carWashService.insertCarBorder(carBorder));
    }

    /**
     * 修改洗车订单
     */
    @RequiresPermissions("orderManagement:carwash:edit")
    @Log(title = "洗车订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarBorder carBorder)
    {
        return toAjax(carWashService.updateCarBorder(carBorder));
    }

    /**
     * 删除洗车订单
     */
    @RequiresPermissions("orderManagement:carwash:remove")
    @Log(title = "洗车订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(carWashService.deleteCarBorderByIds(ids));
    }
}
